package com.remoting.api.registry.bean;

import com.remoting.api.request.RequestType;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 服务导入信息
 * <p>说明:</p>
 * <li></li>
 * @author DuanYong
 * @since 2017年3月3日上午9:43:47
 */
public class ServiceImportInfo {
	/**服务 ID*/
	private String serviceId;
	/**api*/
	private String api;
	/**请求超时时间:默认值-1->不限制,单位 毫秒*/
	private int timeout = -1;
	/**endpoint*/
	private Endpoint endpoint;
	/**
	 * 请求头信息
	 */
	private HeaderInfo headerInfo;
	/**请求类型:默认post*/
	private String requestType = RequestType.post.value();
	/**URL中附加的参数*/
	private Map<String, String> params = new HashMap<String, String>();
	/**请求参数中附加的参数*/
	private Map<String, String> dataParams = new HashMap<String, String>();
	
	public ServiceImportInfo(String serviceId,String api,String timeout, Endpoint endpoint,HeaderInfo headerInfo,String requestType) {
		this.serviceId = serviceId;
		this.api = api;
		this.timeout = StringUtils.isNumeric(timeout)?Integer.valueOf(timeout).intValue():-1;
		this.endpoint = endpoint;
		this.headerInfo = headerInfo;
		this.requestType = requestType;
	}
	
	public void addMappingParam(String name, String value){
		this.params.put(name, value);
	}
	
	public String getMappingParam(String name){
		return this.params.get(name);
	}
	
	public Map<String, String> getMappingParamMaps(){
		return Collections.unmodifiableMap(this.params);
	}

	public String getServiceId() {
		return this.serviceId;
	}
	public void setServiceId(String serviceId) {
		this.serviceId = serviceId;
	}

	public String getRequestType() {
		return requestType;
	}

	public void setRequestType(String requestType) {
		this.requestType = requestType;
	}

	public Endpoint getEndpoint() {
		return endpoint;
	}

	public void setEndpoint(Endpoint endpoint) {
		this.endpoint = endpoint;
	}

	public Map<String, String> getParams() {
		return params;
	}

	public void setParams(Map<String, String> params) {
		this.params = params;
	}
	public void addDataParam(String name, String value){
		this.dataParams.put(name, value);
	}
	public Map<String, String> getDataParams() {
		return dataParams;
	}

	public String getApi() {
		return api;
	}

	public void setApi(String api) {
		this.api = api;
	}
	

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public HeaderInfo getHeaderInfo() {
		return headerInfo;
	}

	public void setHeaderInfo(HeaderInfo headerInfo) {
		this.headerInfo = headerInfo;
	}
	
}
